package cn.jsl.sync;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer2 {
    public static void main(String[] args) throws Exception {
        //创建生产者
        DefaultMQProducer producer = new DefaultMQProducer("sync-producerGroup");
        //连接nameserver
        producer.setNamesrvAddr("localhost:9876");
        //开启生产者
        producer.start();
        //创建消息
        Message message = new Message("syn", "two", "这是敲的第二遍MQ".getBytes(StandardCharsets.UTF_8));
        //执行消息发送
        SendResult send = producer.send(message);
        //打印查看消息
        System.out.println(send);
        //关闭生产者
        producer.shutdown();
    }
}
